/**
 *
 */
package com.iis.hrms.dao;

import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

/**
 * @author firdaus
 * @date May 9, 2010
 * @time 8:19:27 PM
 */
@Repository
public class GenericDAO {

    @PersistenceContext
    EntityManager em;

    public void insert(Object object) {
        em.persist(object);
        em.flush();
    }

    public void update(Object object) {
        em.merge(object);
        em.flush();
    }

    public void delete(Object object) {
        em.remove(object);
        em.flush();
    }

    @SuppressWarnings("rawtypes")
    public List selectList(String namedQuery, Object object, String namedParameter) {
        return em.createNamedQuery(namedQuery).setParameter(namedParameter, object).getResultList();
    }

    public Object selectObject(String namedQuery, Object object, String namedParameter) {
        return em.createNamedQuery(namedQuery).setParameter(namedParameter, object).getSingleResult();
    }

}
